
package com.yuan.graduate;

import com.yuan.application.BaseActivity;
import com.yuan.control.SettingControl;
import com.yuan.unit.AsyncDataJobHandler;
import com.yuan.unit.ToastHelper;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * 修改密码Activity
 * 
 * @author YUAN
 */
@SuppressLint("HandlerLeak")
public class ChangePsdActivity extends BaseActivity implements OnClickListener {

    private Context mContext = null;
    private Handler mHandler = null;
    private EditText et_pwd, change_et_pw, re_change_et_pw;
    private Button btn_change_psd;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_changepsd);
        mHandler = new Handler() {
            public void handleMessage(Message msg) {
                switch (msg.what)
                {
                    case CHNAGEPWDSUCCEED:
                        ToastHelper.getInstance().shortToast(mContext, "修改密码成功，请重新登陆");
                        startActivity(new Intent(mContext, LoginActivity.class));
                        finish();
                        break;
                    case CHNAGEPWDFILLED:
                        ToastHelper.getInstance().shortToast(mContext, "修改密码失败");
                        et_pwd.setText("");
                        change_et_pw.setText("");
                        re_change_et_pw.setText("");
                        break;
                    default:
                        break;
                }
            }
        };
        initView();
    }

    private void initView() {
        // TODO Auto-generated method stub
        et_pwd = (EditText) findViewById(R.id.et_pwd);
        change_et_pw = (EditText) findViewById(R.id.change_et_pw);
        re_change_et_pw = (EditText) findViewById(R.id.re_change_et_pw);
        btn_change_psd = (Button) findViewById(R.id.btn_change_psd);
        btn_change_psd.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        String pwd = et_pwd.getText().toString().trim();
        String newpwd = change_et_pw.getText().toString().trim();
        String renewpwd = re_change_et_pw.getText().toString().trim();
        if (!pwd.equals(SettingControl.getPsd()))
        {
            
            ToastHelper.getInstance().shortToast(mContext, "旧密码错误");
            return;
        }
        if (!newpwd.equals(renewpwd))
        {
            ToastHelper.getInstance().shortToast(mContext, "两次输入密码不一致");
            return;
        }
        AsyncDataJobHandler.getInstance().changepwd(mHandler, newpwd);
    }

}
